<?php

namespace App\Models\common;

use App\Models\admin\AdminUser;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

/**
 * 操作日志
 */
class OperationLog extends Model
{
    use HasFactory;

    protected $table = 'admin_operation_log';

    public $fillable = ['id', 'method', 'title', 'uid', 'path', 'ip', 'ua', 'param', 'function', 'desc'];

    // 定义关联关系
    public function user()
    {
        return $this->hasOne(AdminUser::class, 'id', 'uid');
    }

    /**
     * 为 array / JSON 序列化准备日期格式
     */
    protected function serializeDate(DateTimeInterface $date): string
    {
        return $date->format('Y-m-d H:i:s');
    }
}
